<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var binaryTreePaths = function (root) {
        let res = []
        function dfs(root, path) {
          if (!root.left && !root.right) {
            return res.push([...path].join('->'))
          }
          if (root.left) {
            path.push(root.left.val)
            dfs(root.left, path)
            path.pop()
          }
          if (root.right) {
            path.push(root.right.val)
            dfs(root.right, path)
            path.pop()
          }
        }
        dfs(root, [root.val])
        return res
      }
    </script>
  </body>
</html>
